
import clientAccount.*;
import roomSystem.*;
import administratorAccount.*;
import billStream.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
import p.*;

public class ClientRoomTest {
	
	public static Set cataSet;
	
	static{
		for(int i=0;i < 100;i++){
			Service.createNew(TestCommon.getRandomStr(10), 
							  TestCommon.getRandomStr(10), 
							  TestCommon.getRandom().nextBoolean(), 
							  new Pair(TestCommon.getRandom().nextDouble(),TestCommon.getUnit()));
		}
		
		cataSet=feedCatagories(10,10);
	}
	
	public Facing feedFacing(){
		switch (TestCommon.getRandom().nextInt(6)){
		case 0:
			return Facing.getInstantce("FRONT_VIEW");
		case 1:
			return Facing.getInstantce("REAR_VIEW");
		case 2:
			return Facing.getInstantce("CITY_VIEW");
		case 3:
			return Facing.getInstantce("SEA_VIEW");
		case 4:
			return Facing.getInstantce("GARDEN_VIEW");
		default:
			return Facing.getInstantce("LAKE_VIEW");
		}
	}
	
	public Speciality feedSpeciality(){
		switch (TestCommon.getRandom().nextInt(3)){
		case 0:
			return Speciality.getInstance("HANDICAPPED_ROOM");
		case 1:
			return Speciality.getInstance("NO_SMOKE");
		default:
			return Speciality.getInstance("WITH_KITCHEN");
		}
	}
	
	public SizeAndFacilities feedSizeAndFacilities(){
		switch (TestCommon.getRandom().nextInt(7)){
		case 0:
			return SizeAndFacilities.getInstance("SINGLE");
		case 1:
			return SizeAndFacilities.getInstance("DOUBLE");
		case 2:
			return SizeAndFacilities.getInstance("STANDARD");
		case 3:
			return SizeAndFacilities.getInstance("TRIPLE");			
		case 4:
			return SizeAndFacilities.getInstance("QUAD");			
		case 5:
			return SizeAndFacilities.getInstance("SUITE");
		default:
			return SizeAndFacilities.getInstance("TSU");
		}
	}
	
	public static Set feedCatagories(int cataSize,int serviceSize){
		System.out.println("------------------------------------------------------------------------\n"+
						   "now feeding data into Catagories and Services: \n");
		
		Set ret=new HashSet();
		for(int i=0;i < cataSize;i++){
			ServiceCatagory sc=new ServiceCatagory();
			ret.add(sc);
			sc.setIsDefault(TestCommon.getRandom().nextBoolean());
			sc.setName(TestCommon.getRandomStr(10));
			sc.setNote(TestCommon.getRandomStr(100));
			Set sl=new HashSet();
			sc.setServicesIncluded(sl);
			System.out.println("#########################\n"+
							   "new serviceCatagory created: \n"+
							   "With name: "+sc.getName()+"\n"+
							   "With note: "+sc.getNote()+"\n"+
							   "With default selection: "+sc.getIsDefault()+"\n");
			for(int j=0;j < serviceSize;j++){
				ServiceWrapper ser=new ServiceWrapper();
				ser.setConcrete(Service.getRandomService().toString());
				Set cs=new HashSet();
				cs.add(sc);
				ser.setCatagoriesIncluded(cs);
				sl.add(ser);
				System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@\n"+
								   "New Service in this catagory created: \n"+
								   "With service: "+ser.getConcrete()+"\n"+
								   "@@@@@@@@@@@@@@@@@@@@@@@@@\n");
			}
			System.out.println("#########################\n");
		}
		
		System.out.println("Cata-Serv. feeding finished.\n");
		System.out.println("------------------------------------------------------------------------\n");
		return ret;
	}

	public RoomType feedRoomType(Room room){
		RoomType rt=new RoomType();
		rt.setRoom(room);
		rt.setFacing(feedFacing().toString());
		rt.setFloor(TestCommon.getRandom().nextInt(10));
		rt.setPartTimeAllowed(TestCommon.getRandom().nextBoolean());
		rt.setPricePerDay(TestCommon.getRandom().nextDouble());
		rt.setPricePerDayUnit(TestCommon.getUnit().toString());
		rt.setPricePerHour(TestCommon.getRandom().nextDouble());
		rt.setPricePerHourUnit(TestCommon.getUnit().toString());
		Set sc=new HashSet();
		Iterator itr=((ServiceCatagory)cataSet.toArray()[TestCommon.getRandom().nextInt(10)]).getServicesIncluded().iterator();
		while(itr.hasNext())
			sc.add(itr.next());
		rt.setServicesAvaliable(sc);
		rt.setSizeAndFacilities(feedSizeAndFacilities().toString());
		rt.setSpeciality(feedSpeciality().toString());
		System.out.println("------------------------------------------------------------------------\n"+
						   "created RoomType:\n"+
						   "With facing: "+rt.getFacing()+"\n"+
						   "With floor: "+rt.getFloor()+"\n"+
						   "With PartTimeAllowed: "+rt.getPartTimeAllowed()+"\n"+
						   "With PricePerDayUnit: "+rt.getPricePerDay()+"(measured by "+rt.getPricePerDayUnit().toString()+")"+"\n"+
						   "With PricePerHourUnit: "+rt.getPricePerHour()+"measured by "+rt.getPricePerHourUnit().toString()+")"+"\n"+
						   "With Services: "+rt.getServicesAvaliable().toString()+"\n"+
						   "With size: "+rt.getSizeAndFacilities()+"\n"+
						   "With Speciality: "+rt.getSpeciality()+"\n"+
						   "------------------------------------------------------------------------\n");
		return rt;
	}
	
	public RoomState feedRoomState(ConcreteBill bill,Set clients,Room room){
		RoomState rs=new RoomState();
		rs.setCurrentBill(bill);
		rs.setCurrentClients(clients);
		Set set=new HashSet();
		rs.setRoom(room);
		for(int i=0;i < 1;i++)
			set.add(RoomState.ConcreteType.getRandomType().toString());
		rs.setStates(set);
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created RoomState: \n"+
						   "With Clients: "+(rs.getCurrentClients() != null ? rs.getCurrentClients().toString() : "null")+"\n"+
						   "With States: "+rs.getStates().toString()+"\n"+
						   "------------------------------------------------------------------------\n");
		
		return rs;
	}
	
	public Room feedRoom(ConcreteBill bill,Set clients){
		System.out.println("##########################\n"+
						   "creating room: \n");
		
		Room room=new Room();
		room.setRoomNumber(TestCommon.getRandomStr(10));
		room.setRoomState(feedRoomState(bill,clients,room));
		room.setRoomType(feedRoomType(room));
		
		System.out.println("room created\n"+
						   "With Room Number: "+room.getRoomNumber()+"\n"+
						   "##########################\n");
		return room;
	}
	
	//-----------------------------------------------------------------------
	//feeding methods for clients
	
	public ClientBasicInfo feedClientBasicInfo(SingleClient client){
		ClientBasicInfo cbi=new ClientBasicInfo();
		cbi.setClient(client);
		cbi.setAddress(TestCommon.getRandomAddress().toString());
		cbi.setAge(TestCommon.getRandom().nextInt(100));
		cbi.setBirthday(TestCommon.getRandomDate());
		cbi.setDocNumber(TestCommon.getRandomStr(20));
		cbi.setDocType(TestCommon.getDocType().toString());
		cbi.setFirstName(TestCommon.getRandomStr(10));
		cbi.setMiddleName(TestCommon.getRandomStr(10));
		cbi.setLastName(TestCommon.getRandomStr(10));
		cbi.setSex(TestCommon.getRandom().nextBoolean());
		cbi.setTelNumber1(TestCommon.getTelNumber().toString());
		cbi.setTelNumber2(TestCommon.getTelNumber().toString());
		cbi.setTelNumber3(TestCommon.getTelNumber().toString());
		cbi.setTelNumber4(TestCommon.getTelNumber().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "ClientBasicInfo created: \n"+
						   "With Address: "+cbi.getAddress()+"\n"+
						   "With Age: "+cbi.getAge()+"\n"+
						   "With Birthday: "+cbi.getBirthday().toGMTString()+"\n"+
						   "With DocNumber: "+cbi.getDocNumber()+"\n"+
						   "With DocType: "+cbi.getDocType()+"\n"+
						   "With FirstName: "+cbi.getFirstName()+"\n"+
						   "With MiddleName: "+cbi.getMiddleName()+"\n"+
						   "With LastName: "+cbi.getLastName()+"\n"+
						   "With sex: "+cbi.getSex()+"\n"+
						   "With TelNumber1: "+cbi.getTelNumber1()+"\n"+
						   "With TelNumber2: "+cbi.getTelNumber2()+"\n"+
						   "With TelNumber3: "+cbi.getTelNumber3()+"\n"+
						   "With TelNumber4: "+cbi.getTelNumber4()+"\n"+
						   "------------------------------------------------------------------------\n");
		
		return cbi;
	}
	
	public SingleClient feedSingleClient(ConcreteBill bill,Set others,Group group,FrontDesk fd,Class c){
		System.out.println("------------------------------------------------------------------------\n"+
						   "Creating SingleClient: \n");
		
		SingleClient sc=(c == SingleClient.class ? new SingleClient() : new VIPClient());
		ClientBillState cbs=new ClientBillState();
		cbs.setIsBillAccountOwner(TestCommon.getRandom().nextBoolean());
		if(cbs.getIsBillAccountOwner())
			cbs.setCurrentBill(bill);
		cbs.setDeposite(TestCommon.getRandom().nextDouble());
		cbs.setDepositeUnit(TestCommon.getUnit().toString());
		sc.setClientBillState(cbs);
		if(others != null)others.add(sc);
		sc.setCurrentRoom(feedRoom(bill,others).getRoomState());
		sc.setGroup(group);
		sc.setIsCurrentInHotel(TestCommon.getRandom().nextBoolean());
		sc.setIsGroupMember(group == null);
		sc.setOperator(fd);
		sc.setPersonalInfo(feedClientBasicInfo(sc));
		sc.setNote(TestCommon.getRandomStr(50));
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created SingleClient: "+"\n"+
						   "With cbs Info: "+"\n"+
						   "@@@@@@@@@@@@@@@@@@@@@@@@@\n"+
						   "With isBillAccountOwner: "+cbs.getIsBillAccountOwner()+"\n"+
						   "With currentBill: "+(cbs.getCurrentBill() == null ? "null" : cbs.getCurrentBill().getId())+"\n"+
						   "With deposite: "+cbs.getDeposite()+"(measured by "+cbs.getDepositeUnit()+")"+"\n"+
						   "@@@@@@@@@@@@@@@@@@@@@@@@@\n"+
						   "With room number: "+(sc.getCurrentRoom() == null ? "null" : sc.getCurrentRoom().getRoom().getId())+"\n"+
						   "With group: "+(sc.getGroup() == null ? "null" : sc.getGroup().getId())+"\n"+
						   "With inHotel: "+sc.getIsCurrentInHotel()+"\n"+
						   "With groupChild: "+sc.getIsGroupMember()+"\n"+
						   "With Operator: "+(fd == null ? "null" : fd.getId())+"\n"+
						   "With personalInfoId: "+sc.getPersonalInfo().getId()+"\n"+
						   "With note: "+sc.getNote()+"\n"+
						   "------------------------------------------------------------------------\n");
		return sc;
	}
	
	public Group feedGroup(SingleClient sc,Set list,FrontDesk fd){
		Group group=new Group();
		group.setNote(TestCommon.getRandomStr(50));
		group.setCustomerNumber(10);
		group.setGroupRegisterer(sc);
		group.setOperator(fd);
		group.setCustomerList(list);
	
		System.out.println("------------------------------------------------------------------------\n"+
						   "created group: "+"\n"+
						   "With note: "+group.getNote()+"\n"+
						   "With customerNumber: "+group.getCustomerNumber()+"\n"+
						   "With registererId: "+group.getGroupRegisterer()+"\n"+
						   "With operatorId: "+(fd == null ? "null" : fd.getId())+"\n"+
						   "With customers: "+(list == null ? "null" : list.toString())+"\n"+
						   "------------------------------------------------------------------------\n");
		return group;
	}
	
	public ClientVIPInfo feedVIPInfo(VIPClient vip){
		ClientVIPInfo info=new ClientVIPInfo();
		info.setClient(vip);
		info.setPassword(TestCommon.getRandomStr(20));
		info.setPasswordQuestion(TestCommon.getRandomStr(20));
		info.setPasswordQuestionAnswer(TestCommon.getRandomStr(20));
		info.setVipLevel(ClientVIPInfo.Level.getRandomLevel().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created VIPInfo: "+"\n"+
						   "With Client ID: "+(vip == null ? "null" : vip.getId())+"\n"+
						   "With password: "+info.getPassword()+"\n"+
						   "With password question: "+info.getPasswordQuestion()+"\n"+
						   "With password question answer: "+info.getPasswordQuestionAnswer()+"\n"+
						   "With VIP level: "+info.getVipLevel()+"\n"+
						   "------------------------------------------------------------------------\n");
		return info;
	}
	
	public VIPClient feedVIPClient(ConcreteBill bill,Set others,Group group,FrontDesk fd){
		System.out.println("------------------------------------------------------------------------\n"+
						   "creating VIPClient: \n");
		
		VIPClient vip=(VIPClient)feedSingleClient(bill,others,group,fd,VIPClient.class);
		vip.setVipInfo(feedVIPInfo(vip));
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "VIPClient created.\n");
		return vip;
	}
	
	//-----------------------------------------------------------------------
	//feeding methods for bill system
	
	public AccommodatingRec feedAccommodatingRec(Room room,ConcreteBill cb){
		AccommodatingRec aRec=new AccommodatingRec();
		aRec.setBill(cb);
		aRec.setCountByHour(TestCommon.getRandom().nextBoolean());
		aRec.setNote(TestCommon.getRandomStr(50));
		aRec.setPrice(TestCommon.getRandom().nextDouble());
		aRec.setPriceUnit(TestCommon.getUnit().toString());
		aRec.setRoom(room);
		aRec.setTimeFrom(TestCommon.getRandomDate());
		aRec.setTimeTo(TestCommon.getRandomDate());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created AccommodatingRec: "+"\n"+
						   "With bill id: "+aRec.getBill().getId()+"\n"+
						   "With countByHour: "+aRec.getCountByHour()+"\n"+
						   "With note: "+aRec.getNote()+"\n"+
						   "With price: "+aRec.getPrice()+"(measured by "+aRec.getPriceUnit().toString()+")\n"+
						   "With room: "+aRec.getRoom().getId()+"\n"+
						   "With timeFrom: "+aRec.getTimeFrom().toGMTString()+"\n"+
						   "With timeTo: "+aRec.getTimeTo().toGMTString()+"\n"+
						   "------------------------------------------------------------------------\n");
		return aRec;
	}
	
	public ServiceRec feedServiceRec(ConcreteBill bill){
		ServiceRec sRec=new ServiceRec();
		sRec.setBill(bill);
		sRec.setNote(TestCommon.getRandomStr(50));
		sRec.setPiece(TestCommon.getRandom().nextInt(10));
		sRec.setPrice(TestCommon.getRandom().nextDouble());
		sRec.setPriceUnit(TestCommon.getUnit().toString());
		sRec.setService(Service.getRandomService().toString());
	
		System.out.println("------------------------------------------------------------------------\n"+
						   "created serviceRec: \n"+
						   "With bill id: "+sRec.getBill().getId()+"\n"+
						   "With note: "+sRec.getNote()+"\n"+
						   "With piece: "+sRec.getPiece()+"\n"+
						   "With price: "+sRec.getPrice()+"(measured by "+sRec.getPriceUnit().toString()+")\n"+
						   "With service: "+sRec.getService()+"\n"+
						   "------------------------------------------------------------------------\n");
		
		return sRec;
	}
	
	public ConcreteBill feedConcreteBill(Room room,FrontDesk fd,MergedBill billGroup){
		ConcreteBill cb=new ConcreteBill();
		Set accSet=new HashSet();
		int size=TestCommon.getRandom().nextInt(10);
		cb.setServiceList(accSet);
		for(int i=0;i < size;i++)
			accSet.add(feedServiceRec(cb));
		accSet=new HashSet();
		size=TestCommon.getRandom().nextInt(10);
		cb.setAccommodatingList(accSet);
		for(int i=0;i < size;i++)
			accSet.add(feedAccommodatingRec(room,cb));
		cb.setAssociatedRoom(room);
		cb.setBillState(BillState.getRandomState().toString());
		cb.setGroup(billGroup);
		cb.setOperator(fd);
		cb.setPrice(TestCommon.getRandom().nextDouble());
		cb.setPriceUnit(TestCommon.getUnit().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created ConcreteBill: "+"\n"+
						   "With serviceSet: "+cb.getServiceList().toString()+"\n"+
						   "With accSet: "+cb.getAccommodatingList().toString()+"\n"+
						   "With room id: "+(cb.getAssociatedRoom() == null ? "null" : cb.getAssociatedRoom().getId())+"\n"+
						   "With billState: "+cb.getBillState()+"\n"+
						   "With group: "+(cb.getGroup() == null ? "null" : cb.getGroup().getId())+"\n"+
						   "With Operator: "+(cb.getOperator()== null ? "null" : cb.getOperator().getId())+"\n"+
						   "With price: "+cb.getPrice()+"(measured by "+cb.getPriceUnit().toString()+")\n"+
						   "------------------------------------------------------------------------\n");
		return cb;
	}
	
	public MergedBill feedMergedBill(Set bills,MergedBill group,FrontDesk fd){
		MergedBill mb=new MergedBill();
		mb.setBills(bills);
		mb.setGroup(group);
		mb.setOperator(fd);
		mb.setPrice(TestCommon.getRandom().nextDouble());
		mb.setPriceUnit(TestCommon.getUnit().toString());
		mb.setBillState(BillState.getRandomState().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created MergedBill: \n"+
						   "With bill id: "+mb.getBills().toString()+"\n"+
						   "With group id: "+mb.getGroup().getId()+"\n"+
						   "With operator id: "+mb.getOperator().getId()+"\n"+
						   "With Price: "+mb.getPrice()+"(measured by "+mb.getPriceUnit().toString()+")\n"+
						   "With billState: "+mb.getBillState()+"\n"+
						   "------------------------------------------------------------------------\n");
		return mb;
	}
	
	public CorpInfo feedCorpInfo(Employee em,CorporationEntity entity){
		CorpInfo ci=new CorpInfo();
		ci.setCorporationEntity(entity);
		ci.setAbbrName(TestCommon.getRandomStr(5));
		ci.setAddress(TestCommon.getRandomAddress().toString());
		ci.setContact(TestCommon.getRandomStr(10));
		ci.setDepositeRemainder(TestCommon.getRandom().nextDouble());
		ci.setDepositeRemainderUnit(TestCommon.getUnit().toString());
		ci.setFullName(TestCommon.getRandomStr(20));
		ci.setIsCurrentBillSource(TestCommon.getRandom().nextBoolean());
		ci.setNote(TestCommon.getRandomStr(50));
		ci.setRegisterer(em);
		ci.setTelNumber1(TestCommon.getTelNumber().toString());
		ci.setTelNumber2(TestCommon.getTelNumber().toString());
		ci.setTelNumber3(TestCommon.getTelNumber().toString());
		ci.setTelNumber4(TestCommon.getTelNumber().toString());
		ci.setUpperBoundBillPrice(TestCommon.getRandom().nextDouble());
		ci.setUpperBoundBillPriceUnit(TestCommon.getUnit().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created corpInfo: \n"+
						   "With corpEntity: "+ci.getCorporationEntity().getId()+"\n"+
						   "With abbrName: "+ci.getAbbrName()+"\n"+
						   "With address: "+ci.getAddress()+"\n"+
						   "With contact: "+ci.getContact()+"\n"+
						   "With depositePremainder: "+ci.getDepositeRemainder()+"(measured by "+ci.getDepositeRemainderUnit()+")\n"+
						   "With fullName: "+ci.getFullName()+"\n"+
						   "With isCurrentBillSource: "+ci.getIsCurrentBillSource()+"\n"+
						   "With note: "+ci.getNote()+"\n"+
						   "With registerer: "+ci.getRegisterer().getId()+"\n"+
						   "With tel1: "+ci.getTelNumber1()+"\n"+
						   "With tel2: "+ci.getTelNumber2()+"\n"+
						   "With tel3: "+ci.getTelNumber3()+"\n"+
						   "With tel4: "+ci.getTelNumber4()+"\n"+
						   "With upperBoundBillPrice: "+ci.getUpperBoundBillPrice()+"(measured by "+ci.getUpperBoundBillPriceUnit().toString()+")\n"+
						   "------------------------------------------------------------------------\n");
		return ci;
	}
	
	public CorporationEntity feedCorpEntity(Employee em){
		CorporationEntity entity=new CorporationEntity();
		entity.setCorporationInfo(feedCorpInfo(em,entity));
		Set priceSet=new HashSet();
		int size=TestCommon.getRandom().nextInt(10);
		for(int i=0;i < size;i++){
			RoomPrice rp=new RoomPrice();
			rp.setPrice(TestCommon.getRandom().nextDouble());
			rp.setUnit(TestCommon.getUnit().toString());
			priceSet.add(rp);
		}
		entity.setAdjustedRoomPriceList(priceSet);
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "created entity: \n"+
						   "With CorpInfo: "+entity.getCorporationInfo().getId()+"\n"+
						   "With priceSet: "+priceSet.toString()+
						   "------------------------------------------------------------------------\n");
		return entity;
	}
}
